#include <iostream>

using namespace std;

const int N = 20;

int n;
int col[N], dg[N], ndg[N];
char g[N][N];

void dfs(int u)
{
    if (u == n)
    {
        for (int i = 0; i < n; ++i)
        {
            printf("%s", g[i]);
            printf("\n");
        }
        printf("\n");
        return;
    }

    for (int i = 0; i < n; ++i)
    {
        if (!col[i] && !dg[u + i] && !ndg[n - i + u])
        {
            g[u][i] = 'Q';
            col[i] = dg[u + i] = ndg[n - i + u] = true;
            dfs(u + 1);
            col[i] = dg[u + i] = ndg[n - i + u] = false;
            g[u][i] = '.';
        }
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            g[i][j] = '.';
        }
    }

    dfs(0);
    return 0;
}